package com.swssm.waveloop;

import com.swssm.waveloop.R;

import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
 
public class WaveLoopActivity extends TabActivity {
    
    static {
    	System.loadLibrary("audio-tools");
    }
    
    
    LinearLayout mWaveLoopMain;
    ImageButton mNowPlayingBtn;
    TextView mNowPlayingTitle;
    TextView mNowPlayingArtist;
    TextView mNowPlayingAlbum;
    ImageButton mNowPlayingPlayBtn;
	
    
    ComponentName mService = null;
    
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	
    	setContentView(R.layout.main);
    	TabHost tabHost = getTabHost();

    	tabHost.addTab(tabHost.newTabSpec("tab_test1")
    	  	.setIndicator(
    	  			getResources().getString(R.string.tab_playlist), 
    	  			getResources().getDrawable(R.drawable.ic_tab_playlist))    	  	
    	    //.setContent(R.id.view1)
    	  	.setContent( new Intent(this, PlaylistActivity.class) )
    	    
    	); 
    	
    	mWaveLoopMain = (LinearLayout)findViewById(R.id.waveloop_main);
    	
    	if(mService == null)
    	{
    		Intent i = new Intent( this, WaveLoopPlayerService.class);
    		mService = startService(i);
    	}
    	
    }
   
   //액티비티 종료시 재생 강제 종료
   public void onDestroy() {
		super.onDestroy();
   }

	public void onBackPressed()
	{
		
		new AlertDialog.Builder(this)
    	.setTitle( getResources().getString(R.string.alert_quit_message) )
    	.setIcon(android.R.drawable.ic_dialog_alert)
    	//.setCancelable(false)
    	.setPositiveButton( getResources().getString(R.string.quit_button)
    			, new DialogInterface.OnClickListener(){
    		public void onClick(DialogInterface dialog, int which){
    			Intent intent = new Intent();
    			intent.setComponent(mService);
    		    stopService(intent);
    		    mService = null;
    		    
    			finish();
    		}
    	} )
    	.setNegativeButton(getResources().getString(R.string.cancel_button), null)
    	.show();
	}
}